<template>
	<view >
		<u-swiper @change="change" :height="400" :list="liset" :interval="3000" @click="click"></u-swiper>
		
		<view style="border: 0px solid red;margin-top: 50rpx;">
		<u-grid :col="col" style="margin-top: 20rpx;" v-if="!isSwiper" :border="border">
		<u-mask :show="show" @click="show = false"></u-mask>
		
		<u-grid-item style="height: 200px;margin-top: 0rpx;" v-for="(item,index) in tref" :key="index" name="item1" :index="0" @click="itemClick(item.nurl)">
			<view style="border: 0px solid red; width: 100%;height: 50rpx;">
				<view style="width: 33.3%;height: 50rpx;border-right: 1px solid #EAEBEC;float: left;"></view>
				<view style="width: 33.4%;height: 50rpx;border-right: 1px solid #EAEBEC;float: left;"></view>
				
			</view>
			<image style="margin-top: -30px;" class="image" :src="item.url" mode="aspectFill" />
			<view class="grid-text">{{item.text}}</view>
		</u-grid-item>
		</u-grid>
		</view>
		
		<view style="margin-top: 100rpx;" class="u-card-wrap">
			<view style="border: 1px solid #FDF6EC;">
				<view style="width: 100%;height: 100rpx;background-color: #FFFFFF;font-size: 45rpx;font-weight: 700;text-align: center;line-height: 100rpx;">今日通知</view>
			</view>
			<u-card :title="nowWeek" :sub-title="nowTime"  :padding="padding" :border="border">
				<view   v-for="(item,index) in tong" class="" slot="body" :key="index"> 
					<view @click="tongqwwe(item._id)" class="u-body-item u-flex u-border-bottom u-col-between u-p-t-0">
						<view  class="u-body-item-title u-line-2">
							{{item.neiro}}
						</view>
						
						<image  style="margin-left: 150rpx;" :src="item.zhaop[0]"></image>
					</view>
					
				</view>
				
			</u-card>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				liset: [],
				tref: [],
				tong:[],
				imas:[],
				isSwiper: false,
				border: true,
				col: 3,
				
				nowWeek: '',
				nowTime: '',
				
				padding: 20,
				border: true,
				show:false,
				lisettt:""
				
				
			}
		},
	 	onLoad() {
			this.$forceUpdate()
			this.tongzhi()
		 	this.shouquan()
		    
			
		},
		onShow() {

			var that=this
			
			
			
			const db = uniCloud.database();
			db.collection("lunbo")
				.get()
				.then(function(d) {
					that.liset = d.result.data[0].Ico
					that.xuexiao();
					
				})

				
		},
		
		methods: {	
			click() {		
			},
			change(index) {
				// console.log(index);
			},
			itemClick(e){
				uni.navigateTo({
					url:e
				})
			},
			xuexiao(){
				var that=this
				const db = uniCloud.database();
				db.collection("tblshizi")
				.get()
				.then(function(d){
					uni.setStorageSync("bvz",d.result.data)
					that.xuexiaoxx()
					
				})
			},
			xuexiaoxx(){
				var that=this
				const db = uniCloud.database();
				db.collection("jianjie")
				.get()
				.then(function(d){
					uni.setStorageSync("jian",d.result.data)
				})
			},
			tongzhi(){
				var that=this;
				const db = uniCloud.database();
				db.collection("tongzhi")
				.get()
				.then(function(e){
					that.tong=e.result.data
					// for(var i=0;i<e.result.data.length;i++){
					// 	var bb=e.result.data[i].zhaop[i]
					// 	alert(bb)
					// }
					
				})
				.catch()
			},
			tongqwwe(a){
				uni.navigateTo({
					url:"../tongzhi/tongzhi?_id="+a
				})
			},
		  	shouquan(){
				var that=this
				uni.getStorageSync("you")
				if(uni.getStorageSync("you")==""){
					
				 	uni.showModal({
						
						title:"请先登录,如果不登录讲会无法正常使用小程序",
						 success: function (res) {
						        if (res.confirm) {
						           
						           // 获取code 小程序专有，用户登录凭证。
						               uni.login({
						                   provider: 'weixin',
						                   success(login) {
						                       console.log(login);
						                   }
						               })
						               // desc: '用于完善会员资料'  必填 声明获取用户个人信息后的用途，后续会展示在弹窗中
						               uni.getUserProfile({
										   
						                   desc: '用于完善会员资料',  
						                   lang: 'zh_CN',
						                   success(user) {
											 
						                      var par={
						                      	UserName:user.userInfo.nickName,
						                      	Ico:user.userInfo.avatarUrl,
						                      	Position:"J01",
												Age:"1"
						                      }
						                      const db = uniCloud.database();
						                      db.collection("tblUser")
						                      .add(par)
						                      .then(  function(par){
												    
												  uni.setStorageSync("you",user.userInfo.nickName)
												  uni.setStorageSync("wodeye",user.userInfo)
												  
												  that.shou()
												 uni.showLoading({
												     title: '授权成功,祝您使用愉快',
													 
												 });
												 
												 setTimeout(function () {
													
													 uni.hideLoading();
												 }, 3000);
												
						                      })	
																	  
						                   }
						               })
						        } else if (res.cancel) {
						            console.log('用户点击取消');
								
						        }
						    }
					})	
				}else{
					
				}
				
				
				
				
			},		
			shou() {
				if(uni.getStorageSync("you")!=""){
					
					var that = this;
					var par = {
						UserName: uni.getStorageSync("you")
					}
					
					const db = uniCloud.database();
					db.collection("tblUser")
						.where(par)
						.get()
						.then(function(Y) {
						
								if (Y.result.data.length > 0) {
									uni.setStorageSync("jiushidaol",Y.result.data[0]._id)
									var aa = Y.result.data[0].Position
									
									that.ye(aa)
								}
							})
				}
				
						
					
			},
			ye(aa) {
				var that = this
				var par = {
					PositionID: aa
				}
				const db = uniCloud.database();
				db.collection("tbljuese")
					.where(par)
					.get()
					.then(async function(d) {
						
						for (var i = 0; i < d.result.data.length; i++) {
							
							var bb = d.result.data[i].Modular
							
							var par = {
								ModularID: bb
							}
							var ress = await that.myget("tblmoukuai", par)
							
							that.tref[that.tref.length] = {
								text: ress.result.data[0].ModularName,
								nurl: ress.result.data[0].ModularPath,
								url: ress.result.data[0].Ico
							}
							
						}
					})
			},		
			currentTime () {
			  setInterval(this.getDate, 500)
			},
			getDate () {
			  const year = new Date().getFullYear()
			  const month = new Date().getMonth() + 1 < 10 ? '0' + (new Date().getMonth() + 1) : (new Date().getMonth() + 1)
			  const date = new Date().getDate() < 10 ? '0' + new Date().getDate() : new Date().getDate()
			  const hh = new Date().getHours() < 10 ? '0' + new Date().getHours() : new Date().getHours()
			  const mm = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes()
			  const ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds()
			  const week = new Date().getDay()
			  this.nowTime = year + '年' + month + '月' + date + '日' + ' ' + hh + ':' + mm + ':' + ss
			  if (week === 1) {
			    this.nowWeek = '星期一'
			  } else if (week === 2) {
			    this.nowWeek = '星期二'
			  } else if (week === 3) {
			    this.nowWeek = '星期三'
			  } else if (week === 4) {
			    this.nowWeek = '星期四'
			  } else if (week === 5) {
			    this.nowWeek = '星期五'
			  } else if (week === 6) {
			    this.nowWeek = '星期六'
			  } else if (week === 27) {
			    this.nowWeek = '星期日'
			  }
			}
		},
  mounted () {
    this.currentTime()
  },
  // 销毁定时器
  beforeDestroy: function () {
    if (this.getDate) {
      clearInterval(this.getDate) // 在Vue实例销毁前，清除时间定时器
    }
  }
}
	
</script>

<style scoped lang="scss">
.grid-text {
	font-size: 28rpx;
	margin-top: 4rpx;
	color: $u-type-info;
}
.image{
	width: 50px;
	height: 50px;
	margin-top: 50px;
}

	.u-demo {
		padding-top: 0;
	}
	
	.u-card-wrap { 
		background-color: $u-bg-color;
		padding: 1px;
	}
	
	.u-body-item {
		font-size: 32rpx;
		color: #333;
		padding: 20rpx 10rpx;
	}
		
	.u-body-item image {
		width: 120rpx;
		flex: 0 0 120rpx;
		height: 120rpx;
		border-radius: 8rpx;
		margin-left: 12rpx;
	}

</style>
